

namespace Core.Features
{
    using System;
    using Base;
    using Contracts.Enums;
    using Resources;
    using Contracts.Interfaces;
    using System.Linq;

    
    public sealed class DemobilizerResistance<T> : FeatureBase<object>
    {
        public DemobilizerResistance(){}

        public DemobilizerResistance(T value) 
            : base(value){ }
        /// <summary>
        /// Obtains the feature name
        /// </summary>
        public override string Name
        {
            get { return "Demobilizer resistance"; }
        }
        /// <summary>
        /// Obtains the feature group
        /// </summary>
        public override FeatureGroupsEnum FeatureGroup{ get { return FeatureGroupsEnum.Defence; } }
        /// <summary>
        /// Obtains the feature type
        /// </summary>
        public override FeaturesEnum FeatureType { get { return FeaturesEnum.DemobilizerResistance; } }
        /// <summary>
        /// Obtains or defines the feature unit
        /// </summary>
        public override string Unit { get { return Traduction.label_unit_percent; } }

        public override void SetModifiedValue(IAgent agent, IRobot robot)
        {
            if (agent == null || robot == null) return;
            
            double moduleBonus = robot.Modules.SumModifiersValues(FeatureTypesEnum.Robot, this.FeatureType);

            ModifiedValue = IsRounded
                ? Math.Round(moduleBonus, 0, MidpointRounding.AwayFromZero)
                : Math.Round(moduleBonus, 2);
        }

        public override string FormattedValue
        {
            get { return String.Format("{0} {1}", IsModified ? (double)ModifiedValue * 100 : (double)Value * 100, Unit); }
        }
    }
}